package com.yuexunit.operationman.nbsy.module.OperationInventory.ui;

import android.content.Intent;
import android.view.View;
import android.widget.BaseAdapter;
import android.widget.TextView;


import com.yuexunit.operationman.nbsy.R;
import com.yuexunit.operationman.nbsy.base.BaseKJActivity;
import com.yuexunit.operationman.nbsy.config.AppConfig;
import com.yuexunit.operationman.nbsy.module.OperationInventory.adapter.TempletAdapter;
import com.yuexunit.operationman.nbsy.module.OperationInventory.bean.TempletBean;
import com.yuexunit.operationman.nbsy.module.OperationInventory.model.impl.TempletModel;
import com.yuexunit.operationman.nbsy.module.OperationInventory.presenter.ITempletPresenter;
import com.yuexunit.operationman.nbsy.module.OperationInventory.presenter.impl.TempletPresenter;
import com.yuexunit.operationman.nbsy.module.OperationInventory.ui.view.ITempletView;
import com.yuexunit.operationman.nbsy.widget.FixedSwipeListView;
import com.yuexunit.operationman.nbsy.widget.LoadingDialog;

import org.kymjs.kjframe.utils.PreferenceHelper;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by work-jx on 2017/9/4.
 */
public class Act_OperationInventory_Templet extends BaseKJActivity implements ITempletView{

    @Bind(R.id.tv_patient_name)
    TextView tvPatientName;
    @Bind(R.id.tv_patient_sex)
    TextView tvPatientSex;
    @Bind(R.id.tv_patient_visitno)
    TextView tvPatientVisitno;
    @Bind(R.id.tv_patient_disease)
    TextView tvPatientDisease;
    @Bind(R.id.listview)
    FixedSwipeListView listview;

    BaseAdapter adapter;
    ITempletPresenter presenter;
    LoadingDialog loadingDialog;

    ArrayList<TempletBean.ObjectEntity> objectEntities = new ArrayList<TempletBean.ObjectEntity>();

    @Override
    public void setRootView() {
        setContentView(R.layout.act_operationinventory_templet);
        ButterKnife.bind(this);
    }

    @Override
    public void initData() {
        super.initData();
        setTitle();
        loadingDialog = new LoadingDialog(this);
        presenter = new TempletPresenter(this,new TempletModel());
    }

    @Override
    public void onResume(){
        super.onResume();
        Map<String, String> params = new HashMap<>();
        presenter.getTempletDate(params);
    }

    private void setTitle() {
        tvPatientName.setText(AppConfig.INVENTORYBEAN.getObject().getCheck().getPatientName());
        if (AppConfig.INVENTORYBEAN.getObject().getCheck().getPatientSex().equals("1")) {
            tvPatientSex.setText("男");
        } else if (AppConfig.INVENTORYBEAN.getObject().getCheck().getPatientSex().equals("2")) {
            tvPatientSex.setText("女");
        } else {
            tvPatientSex.setText("不详");
        }
        tvPatientVisitno.setText("住院号" + AppConfig.INVENTORYBEAN.getObject().getCheck().getInHospitalNo());
        tvPatientDisease.setText(PreferenceHelper.readString(aty, AppConfig.PATIENT_INFO, AppConfig.PATIENT_DISEASE));
    }

    @OnClick({R.id.titlebar_docadvice_img_back, R.id.templet_ll})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.titlebar_docadvice_img_back:
                finish();
                break;
            case R.id.templet_ll:
                Intent intent = new Intent(aty, Act_OperationInventory_SelectTemplet.class);
                intent.putExtra("type","1");
                aty.startActivity(intent);
                finish();
                break;
        }
    }


    @Override
    public void getTempletDate(TempletBean templetBean) {
        if(templetBean.getCode() == 200)
        {
            objectEntities = templetBean.getObject();
            adapter = new TempletAdapter(listview,objectEntities,R.layout.item_operationinventory_templet,(Act_OperationInventory_Templet)aty);
            listview.setAdapter(adapter);
        }
    }

    @Override
    public void loadingDialogStatus(int status) {
        switch (status) {
            case AppConfig.SHOW_DIALOG:
                loadingDialog.setCanceledOnTouchOutside(false);
                loadingDialog.show();
                break;
            case AppConfig.DISMISS_DIALOG:
                loadingDialog.dismiss();
                break;

        }
    }
}
